﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows;

namespace Cheems.Control.Converters
{
    /// <summary>
    /// bool值转控件可见性
    /// </summary>
    public class BoolToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool boolValue)
            {
                // 默认情况下，如果为 true 返回 Visible, false 返回 Collapsed
                Visibility result = boolValue ? Visibility.Visible : Visibility.Collapsed;

                // 如果 parameter 是 "reverse"，反转返回的值
                if (parameter is string param && param.Equals("reverse", StringComparison.OrdinalIgnoreCase))
                {
                    result = boolValue ? Visibility.Collapsed : Visibility.Visible;
                }

                return result;
            }

            return Visibility.Collapsed; // 默认返回 Collapsed
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // 可选：如果你不需要双向绑定，可以返回 DependencyProperty.UnsetValue
            return DependencyProperty.UnsetValue;
        }
    }

}
